import 'package:flutter/material.dart';

/// 通用提示组件
/// 支持自定义图标、文字、颜色等属性
class HintTipWidget extends StatelessWidget {
  /// 提示文字
  final String text;
  
  /// 图标
  final IconData icon;
  
  /// 背景颜色
  final Color backgroundColor;
  
  /// 文字颜色
  final Color textColor;
  
  /// 图标颜色
  final Color iconColor;
  
  /// 文字大小
  final double fontSize;
  
  /// 图标大小
  final double iconSize;
  
  /// 圆角半径
  final double borderRadius;
  
  /// 内边距
  final EdgeInsetsGeometry padding;
  
  /// 图标和文字之间的间距
  final double spacing;
  
  /// 布局方向
  final Axis direction;
  
  /// 是否显示动画效果
  final bool animated;

  const HintTipWidget({
    Key? key,
    required this.text,
    required this.icon,
    this.backgroundColor = const Color(0x33000000), // Colors.black.withOpacity(0.2)
    this.textColor = Colors.white,
    this.iconColor = Colors.white,
    this.fontSize = 12,
    this.iconSize = 16,
    this.borderRadius = 15,
    this.padding = const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
    this.spacing = 8,
    this.direction = Axis.horizontal,
    this.animated = true,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    Widget content = Container(
      padding: padding,
      decoration: BoxDecoration(
        color: backgroundColor,
        borderRadius: BorderRadius.circular(borderRadius),
      ),
      child: _buildContent(),
    );

    // 如果启用动画，添加渐入动画效果
    if (animated) {
      return TweenAnimationBuilder<double>(
        duration: const Duration(milliseconds: 800),
        curve: Curves.easeInOut,
        tween: Tween(begin: 0.0, end: 1.0),
        builder: (context, value, child) {
          return Opacity(
            opacity: value,
            child: Transform.scale(
              scale: 0.8 + (0.2 * value),
              child: content,
            ),
          );
        },
      );
    }

    return content;
  }

  /// 构建内容布局
  Widget _buildContent() {
    final iconWidget = Icon(
      icon,
      color: iconColor,
      size: iconSize,
    );

    final textWidget = Text(
      text,
      style: TextStyle(
        color: textColor,
        fontSize: fontSize,
        fontWeight: FontWeight.w500,
      ),
    );

    if (direction == Axis.horizontal) {
      return Row(
        mainAxisSize: MainAxisSize.min,
        children: [
          iconWidget,
          SizedBox(width: spacing),
          textWidget,
        ],
      );
    } else {
      return Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          iconWidget,
          SizedBox(height: spacing),
          textWidget,
        ],
      );
    }
  }

  /// 预设样式工厂方法

  /// 滑动提示样式
  factory HintTipWidget.swipe({
    String text = '上下滑动浏览更多页面',
    IconData icon = Icons.swipe_vertical,
  }) {
    return HintTipWidget(
      text: text,
      icon: icon,
    );
  }

  /// 点击提示样式
  factory HintTipWidget.tap({
    String text = '点击查看详情',
    IconData icon = Icons.touch_app,
  }) {
    return HintTipWidget(
      text: text,
      icon: icon,
    );
  }

  /// 搜索提示样式
  factory HintTipWidget.search({
    String text = '搜索内容',
    IconData icon = Icons.search,
  }) {
    return HintTipWidget(
      text: text,
      icon: icon,
    );
  }

  /// 刷新提示样式
  factory HintTipWidget.refresh({
    String text = '下拉刷新数据',
    IconData icon = Icons.refresh,
  }) {
    return HintTipWidget(
      text: text,
      icon: icon,
    );
  }

  /// 加载提示样式
  factory HintTipWidget.loading({
    String text = '正在加载...',
    IconData icon = Icons.hourglass_empty,
  }) {
    return HintTipWidget(
      text: text,
      icon: icon,
    );
  }

  /// 成功提示样式
  factory HintTipWidget.success({
    String text = '操作成功',
    IconData icon = Icons.check_circle_outline,
    Color backgroundColor = const Color(0x334CAF50), // 绿色背景
  }) {
    return HintTipWidget(
      text: text,
      icon: icon,
      backgroundColor: backgroundColor,
    );
  }

  /// 错误提示样式
  factory HintTipWidget.error({
    String text = '操作失败',
    IconData icon = Icons.error_outline,
    Color backgroundColor = const Color(0x33F44336), // 红色背景
  }) {
    return HintTipWidget(
      text: text,
      icon: icon,
      backgroundColor: backgroundColor,
    );
  }

  /// 警告提示样式
  factory HintTipWidget.warning({
    String text = '请注意',
    IconData icon = Icons.warning_outlined,
    Color backgroundColor = const Color(0x33FF9800), // 橙色背景
  }) {
    return HintTipWidget(
      text: text,
      icon: icon,
      backgroundColor: backgroundColor,
    );
  }

  /// 信息提示样式
  factory HintTipWidget.info({
    String text = '提示信息',
    IconData icon = Icons.info_outline,
    Color backgroundColor = const Color(0x332196F3), // 蓝色背景
  }) {
    return HintTipWidget(
      text: text,
      icon: icon,
      backgroundColor: backgroundColor,
    );
  }

  /// 自定义样式
  factory HintTipWidget.custom({
    required String text,
    required IconData icon,
    required Color backgroundColor,
    Color textColor = Colors.white,
    Color iconColor = Colors.white,
    double fontSize = 12,
    double iconSize = 16,
    double borderRadius = 15,
    EdgeInsetsGeometry padding = const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
    double spacing = 8,
    Axis direction = Axis.horizontal,
    bool animated = true,
  }) {
    return HintTipWidget(
      text: text,
      icon: icon,
      backgroundColor: backgroundColor,
      textColor: textColor,
      iconColor: iconColor,
      fontSize: fontSize,
      iconSize: iconSize,
      borderRadius: borderRadius,
      padding: padding,
      spacing: spacing,
      direction: direction,
      animated: animated,
    );
  }
}
